[#assign menucode="quoteOrder"]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <title>我的订单</title>
    <link href="/res/css/respective/order/back-order.css" rel="stylesheet">
    <style type="text/css">
        .back-main a {
            text-decoration: none !important;
        }
		.layui-layer-content{
			padding-bottom: 10px;
		}
        .blueBtn {
            display: inline-block;
            height: 32px;
            line-height: 32px;
            margin: 3px 0;
            text-align: center;
            color: #fff;
            background: #00b1db;
            border-radius: 3px;
            cursor: pointer;
            padding: 0 10px;
        }

        .grayBtn {
            display: inline-block;
            height: 32px;
            line-height: 32px;
            margin: 3px 0;
            text-align: center;
            color: #fff;
            background: gray;
            border-radius: 3px;
            cursor: pointer;
            padding: 0 10px;
        }

        .dataTable .alltd .cname .tan-companyInfo {
            display: none;
        }

        .dataTable .alltd .cname:hover .tan-companyInfo {
            display: block;
        }

        .peo .tan-peoInfo {
            display: none;  
            position: absolute;
            left: -100px;
            bottom:30px;
            width: 260px;
            height: auto;
            padding: 8px; 
            border: 1px solid #cfcfcf;
            background: #fff;
            z-index: 3;
        }

        .peo:hover .tan-peoInfo {
            display: block;
        }

        .tan-peoInfo em {
            position: absolute;
            width: 11px;
            height: 6px;
            left: 110px;
            bottom: -6px;
            background: url(/res/images/backicon.png) no-repeat -26px -312px;
        }

        .tan-peoInfo .des {
            padding: 5px 0 0 5px;
        }

        .tan-peoInfo .des p {
            text-align: left;
            line-height: 26px;
        }
    </style>
</head>
<body>
[#-- ispurchaser是否是采购商 --]
[#assign ispurchaser = Session.currentRole.roleType == 1]
<div class="warp">
[#include "/front/common/front_headAzt.html"]
    <div class="backcontent">
    [#include "/front/common/front_leftAzt.html"]

        <div class="back-main">
            <div class="inner">
                <div class="title">项目订单</div>
                <div class="backTab">
                    <ul>
                        <li [#if queryParam.tab == 0]class="on"[/#if] data-tab="0">全部订单</li>
                        <li [#if queryParam.tab == 1]class="on"[/#if] data-tab="1">待[#if !ispurchaser]买家[/#if]付款 [#if unPayOrderCount > 0]<span class="orange"><i></i>${unPayOrderCount!}</span>[/#if]</li>
                        <li [#if queryParam.tab == 2]class="on"[/#if] data-tab="2">已付款 [#if payedOrderCount > 0]<span class="orange"><i></i>${payedOrderCount!}</span>[/#if]</li>
                        <li [#if queryParam.tab == 3]class="on"[/#if] data-tab="3">已发货 [#if sendedOrderCount > 0]<span class="orange"><i></i>${sendedOrderCount!}</span>[/#if]</li>
                    [#if showChildCompanyTab]
                        <li [#if queryParam.tab == 10]class="on"[/#if] data-tab="10">分公司的订单 [#if childCompanyOrderCount > 0]<span class="orange"><i></i>${childCompanyOrderCount!}</span>[/#if]</li>
                    [/#if]
                    </ul>
                </div>
                <form id="orderForm" action="/order/quote" method="get">
                    <!-- 当前页码 -->
                    <input type="hidden" id="pageNo" name="pageNo" value="${page.pageNum!}">
                    <!-- 订单tab -->
                    <input type="hidden" id="tab" name="tab" value="${queryParam.tab!}">
                    <input type="hidden" id="state" name="state" value="${queryParam.state!}">

                    <div class="back-status"> 
                        <input style="width: 175px;" type="text" id="keyword" name="keyword" value="${queryParam.keyword!}" placeholder="请输入询价单名称/订单编号" class="orderInput orderInput1" />
                        <span>
                            <label>[#if ispurchaser]卖[#else]买[/#if]家名称：</label>
                            <input type="text" class="orderInput orderInput2"
                                   [#if ispurchaser]id="sellerCompanyName" name="sellerCompanyName" value="${queryParam.sellerCompanyName!}"
                                   [#else]id="buyerCompanyName" name="buyerCompanyName" value="${queryParam.buyerCompanyName!}"[/#if]/>
                        </span>
                    [#if queryParam.tab == 0 || queryParam.tab == 10]
                        <span>
                            订单状态：
                            <select id="select_state" onchange="$('#state').val(this.value)" style="-webkit-appearance: none; -moz-appearance: none; appearance: none; background: url('/res/images/respective/company/jt.png') no-repeat right 2px">
                                <option value="">全部订单</option>
                                [#list orderStateMap?keys as orderStateValue ]
                                    <option value="${orderStateValue}" [#if orderStateValue == queryParam.state!]selected[/#if] >${orderStateMap[orderStateValue]}</option>
                                [/#list]
                            </select>
                        </span>
                    [/#if]
                        <span>
                            下单日期：
                            <input type="text" id="sdate" name="sdate" value="${queryParam.sdate!}" class="orderInput dateInput" /> - <input type="text" id="edate" name="edate" value="${queryParam.edate!}" class="orderInput dateInput" /></span>
                    		<a href="javascript:search()">搜索</a>
                    </div>
                </form>
                <table class="titleTable">
                    <tbody>
                    <tr style="background-color: #f8f8f8;">
                        <td width="24%">询价单名称</td>
                        <td width="19%">收货人</td>
                        <td width="19%">金额</td>
                        <td width="19%">订单状态</td>
                        <td width="19%">操作</td>
                    </tr>
                    </tbody>
                </table>
                <div class="dataTable">

                [#if orderList?? && orderList?size > 0]
                    [#list orderList as order]
                        [#-- 当前订单是否能申请发货/立即发货 --]
                        [#assign canShip = !order.isShipEnd && order.state != 0 && order.state != 4]
                        <table data-orderId="${order.id!}" data-buyerCompanyId="${order.buyerCompanyId!}" data-buyerUserId="${order.buyerUserId!}"
                               data-sellerCompanyId="${order.sellerCompanyId!}" data-sellerUserId="${order.sellerUserId!}">
                            <tbody>
                            <tr>
                                <th colspan="5">
                                    <div class="alltd">
                                        下单时间：${order.ordertime!}　　订单号：${order.orderNumber!} &nbsp; &nbsp; &nbsp;
                                        <div class="cname">
                                            [#if ispurchaser]
                                                卖家：<a href="/shop/company/${order.sellerCompanyId!}" target="_blank">${CommonUtil.getSimpleStr(order.sellerCompanyName!, 20)}</a>
                                            [#else]
                                                [#if order.topCompanyName??]
                                                买家：${CommonUtil.getSimpleStr(order.topCompanyName!, 20)}
                                                &nbsp; &nbsp; &nbsp;
                                                分公司：${CommonUtil.getSimpleStr(order.buyerCompanyName!, 20)}
                                                [#else]
                                                    买家：${CommonUtil.getSimpleStr(order.buyerCompanyName!, 20)}
                                                [/#if]
                                            [/#if]
                                            [#if (ispurchaser && order.sellerUserId??) || (!ispurchaser && order.buyerUserId??)]
                                                <div class="tan-companyInfo" [#if order.topCompanyName??]style="left: 218px;"[/#if]>
                                                    <div style="text-align: center; padding-top: 35px;">
                                                        <img src="/res/third/nice-validator/images/loading.gif" alt="loading" data-img="loading"/>
                                                    </div>
                                                </div>
                                            [/#if]
                                        </div>
                                        [#if queryParam.tab = 10]&nbsp; &nbsp; &nbsp;分公司：${order.buyerCompanyName!}[/#if]
                                    </div>
                                </th>
                            </tr>
                            <tr>
                                <td width="24%">
                                    <p class="name" title="项目名称：${order.projectName!}">
                                        <a href="/xmh/${order.enquiryId!}" target="_blank">${order.enquiryName!}</a>
                                    </p>
                                </td>
                                <td width="19%">
                                    <div class="peo" style="position: relative;">
                                        ${order.receiptName!}
                                        <div class="tan-peoInfo">
                                            <div style="text-align: center; padding-top: 35px;">
                                                <img src="/res/third/nice-validator/images/loading.gif" alt="loading" data-img="loading"/>
                                            </div>
                                            <em></em>
                                        </div>
                                    </div>
                                </td>
                                <td width="19%">
                                    <b class="orange">￥${order.totalPrice!?string('0.00')}</b>
                                    [#if order.ifBatchPay?? && order.ifBatchPay == 1]
                                        <div class="pici">
                                            <span class="pname" data-tip="batchPay">分批</span>
                                            <div class="pcdown">
                                                <img src="/res/third/nice-validator/images/loading.gif" alt="loading"/>
                                            </div>
                                        </div>
                                    [/#if]
                                </td>
                                <td width="19%">
                                    <div>${orderStateMap[order.state?string]!}
                                        [#if order.ifBatchShip?? && order.ifBatchShip == 1]
                                            <div class="pici pici2">
                                                <span class="pname" data-tip="batchShip">分批</span>
                                                <div class="pcdown">
                                                    <img src="/res/third/nice-validator/images/loading.gif" alt="loading"/>
                                                </div>
                                            </div>
                                        [/#if]
                                    </div>
                                    [#if order.message?? && order.message != '']
                                        <div class="msg"><span></span> <p><i></i><b>留言</b>：${order.message!}</p></div>
                                    [/#if]
                                    <p><a href="/order/${order.id!}" target="_blank">订单详情</a></p>
                                </td>
                                <td width="19%">
                                    [#if queryParam.tab?? && queryParam.tab = 10]
                                        [#-- 总公司只能帮分公司支付，其余操作都是不允许的 --]
                                        [#else]
                                            [#if ispurchaser]
                                                [#if canShip]
                                                    <a href="/order/ship/${order.id!}" target="_blank" class="btn">申请发货</a><br>
                                                [/#if]
                                                [#if order.unSignShipId?? && order.state != 0 && order.state != 4]
                                                    <a href="/order/ship/${order.id!}?shipId=${order.unSignShipId!}" target="_blank" class="btn">确认收货</a><br>
                                                [/#if]
                                                [#if order.unPayId?? && order.state != 0 && order.state != 4]
                                                    <a href="javascript:void(0)" onclick="goPay('${order.id!}', '${order.unPayId!}')" class="btn">支付</a><br>
                                                [/#if]
                                            [#else]
                                                [#if order.state != 0 && order.state != 4 && (canShip || order.unShipedShipId??)]
                                                    <a href="/order/ship/${order.id}" target="_blank" class="btn">立即发货</a><br>
                                                [/#if]
                                                [#if order.state == 1]
                                                    <p><a href="javascript:void(0)" onclick="showModifyPriceWin(${order.id!}, '${order.totalPrice!}','${order.originalPrice!}')">修改价格</a></p>
                                                [/#if]
                                            [/#if]
                                            [#if order.state == 1 && order.paidSize == 0]
                                                <p><a href="javascript:void(0)" onclick="showCancelOrderWin(${order.id!})">取消订单</a></p>
                                            [/#if]
                                    [/#if]
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    [/#list]

                    </div>
                    <div class="backpage">
                        共${page.total!}条订单记录<span class="orange">${page.pageNum!}</span> / ${page.pages!}
                        <p>
                            <input type="text" id="gotoPage"/>
                            <a href="javascript:void(0)" class="go" onclick="goto($('#gotoPage').val())">GO</a>
                        </p>
                        <div class="pnt">
                            <a href="javascript:void(0)" class="prev" onclick="pre()"></a>
                            <a href="javascript:void(0)" class="next" onclick="next()"></a>
                        </div>
                    </div>
                [#else]
                    <div style="text-align: center">当前没有任何订单信息~</div>
                [/#if]
            </div>
        </div>
    </div>

[#include "/front/common/front_footerAzt.html"]
</div>

<!-- 公司信息悬浮框Template -->
<script type="text/html" id="companyTip">
    <em></em>
    <div class="pic" onclick="window.open('/shop/company/[:=this.companyId||'':]')" style="cursor: pointer;">
        <img src="[:=this.logo||'/res/images/temppic2.jpg':]" alt="" width="80px" height="80px"/>
    </div>
    <div class="des">
        <p><a href="/shop/company/[:=this.companyId||'':]" target="_blank">[:=this.companyName||'':]</a></p>
        <p>[:=this.regProvince||'':] [:=this.regCity||'':]</p>
        <p>[:=this.userName||'':]     [:=this.contact||'':]</p>
    </div>
</script>

<!-- 收货人悬浮框Template -->
<script type="text/html" id="peoTip">
    <em></em>
    <div class="des">
        <p>{{ d.receiptName||'' }}</p>
        <p>{{ d.receiptProvinceName||'' }} {{ d.receiptCityName||'' }} {{ d.receiptAreaName||'' }} {{ d.receiptAddress||'' }}</p>
        <p>{{ d.receiptTel||d.receiptPhone||'' }}</p>
    </div>
</script>

<!-- 分批支付悬浮框Template -->
<script type="text/html" id="batchPayTip">
    <div class="pctitle">分批付款</div>
    <em></em>
    <ul>
        [: for(var i = 0, len = list.length; i < len; i++) { :]
        <li class="[: if(i != len - 1) { :]first[: } :][: if(i == len - 1) { :]on[: } :]">
            <div class="num"><i></i><span>[:= i + 1 :]</span></div>
            <p class="price"><span class="orange">¥[:=list[i].payPrice.toFixed(2):]</span></p>
            [: if(list[i].payResult == 1) { :]
            <p>支付凭证审核中</p>
            [: } :]
            [: if(list[i].payResult == 3) { :]
            <p>支付待复核</p>
            [: } :]
            [: if(list[i].ppState == 1) { :]
            <p>支付待解冻</p>
            [: } :]
            <p>[:=list[i].payTime:]</p>
        </li>
        [: } :]
        [: if(this.unPayPrice) { :]
        <li>
            <div class="num"><i></i><span>[:= len + 1 :]</span></div>
            <p class="price"> 剩余：<span class="orange">¥[:=this.unPayPrice.toFixed(2)||'':]</span></p>
        </li>
        [: } :]
    </ul>
</script>

<!-- 分批发货悬浮框Template -->
<script type="text/html" id="batchShipTip">
    <div class="pctitle">分批发货</div>
    <em></em>
    <ul>
        [: for(var i = 0, len = list.length; i < len; i++) { :]
        <li class="[: if(i != len - 1) { :]first[: } :][: if(i == len - 1) { :]on[: } :]">
            <div class="num"><i></i><span>[:= i + 1 :]</span></div>
            [: if(this.list[i].applyPrice) { :]
            <p class="price">请货金额<br /><span class="orange">¥[:=list[i].applyPrice:]</span> </p>
            [: } else { :]
            <p class="price">未请货<br><span class="orange">&nbsp;</span></p>
            [: } :]
            [: if(this.list[i].shipPrice) { :]
            <p class="price">发货金额<br /><span class="orange">¥[:=list[i].shipPrice:]</span> </p>
            <p>[:=list[i].shipTime:]</p>
            [: } else { :]
            <p class="price">发货状态<br>未发</p>
            [: } :]
        </li>
        [: } :]
        [: if(this.unShipPrice) { :]
        <li>
            <div class="num"><i></i><span>[:= list.length + 1 :]</span></div>
            <p class="price"> 剩余货物<br><span class="orange">¥[:=this.unShipPrice||'':]</span></p>
        </li>
        [: } :]
    </ul>
</script>

<!-- 取消订单 -->
<div class="tanbox tan-resetOrder" id="cancelOrderWin" style="display: none;">
    <input type="hidden" name="orderId">
    <div class="tanbg"></div>
    <div class="box">
        <div class="title"><span class="closed"></span>取消订单</div>
        <div class="cont">
            <p>请选择您取消订单的原因：</p>
            <ul class="fix">
                [#if ispurchaser]
                    <li><label><span class="radioModel radioModelon"><input type="radio" name="cancelReason" checked="checked" value="信息有误，重新下单"/></span> 信息有误，重新下单</label></li>
                    <li><label><span class="radioModel"><input type="radio" name="cancelReason" value="不需要货品了"/></span> 不需要货品了 </label></li>
                    <li><label><span class="radioModel"><input type="radio" name="cancelReason" value="付款遇到问题"/></span> 付款遇到问题  </label></li>
                    <li><label><span class="radioModel"><input type="radio" name="cancelReason" value="其他"/></span> 其他 </label></li>
                [#else]
                    <li><label><span class="radioModel radioModelon"><input type="radio" name="cancelReason" checked="checked" value="无法备齐货"/></span> 无法备齐货 </label></li>
                    <li><label><span class="radioModel"><input type="radio" name="cancelReason" value="不是有效的订单"/></span> 不是有效的订单 </label></li>
                    <li><label><span class="radioModel"><input type="radio" name="cancelReason" value="货款支付问题"/></span> 货款支付问题  </label></li>
                    <li><label><span class="radioModel"><input type="radio" name="cancelReason" value="其他"/></span> 其他 </label></li>
                [/#if]
            </ul>
            <div class="tarea">
                <textarea placeholder="补充说明" name="cancelInstr" style="resize: vertical; outline: none; color: #666;" onkeyup="checkCancelInstr()"></textarea>
                <p>0/500</p>
            </div>
            <p class="error" style="display: none;"><i></i>请选择一个原因</p>
            [#if ispurchaser]
             <div class="btn">
                <a class="sav" href="javascript:void(0)" onclick="cancelOrder()">确定</a>
                <a href="javascript:void(0)" onclick="$('#cancelOrderWin').hide();">取消</a>
            </div>
            [#else]
             <div class="btn suply">
                <a class="sav" href="javascript:void(0)" onclick="cancelOrder()">确定</a>
                <a href="javascript:void(0)" onclick="$('#cancelOrderWin').hide();">取消</a>
            </div>
            [/#if] 
        </div>
    </div>
</div>

<!-- 修改价格弹出框 -->
<div class="tanbox tan-editprice" id="modifyPriceWin" style="display: none;">
    <input type="hidden" name="orderId">
    <input type="hidden" name="maxPrice">
    <div class="tanbg"></div>
    <div class="box" style="width: 450px;">
        <div class="title"><span class="closed"></span>修改价格</div>
        <div class="cont">
            <div class="inputDiv">
                <input type="text" placeholder="输入价格" name="price"/> 应付总额：<span class="orange"></span></div>
             [#if ispurchaser]
            <div class="btn btn-left">
                <a class="sav" href="javascript:void(0)" onclick="modifyPrice()">确定</a>
                <a href="javascript:void(0)" onclick="$('#modifyPriceWin').hide()">取消</a>
            </div>
            [#else]
             <div class="btn btn-left suply">
                <a class="sav" href="javascript:void(0)" onclick="modifyPrice()">确定</a>
                <a href="javascript:void(0)" onclick="$('#modifyPriceWin').hide()">取消</a>
            </div>
             [/#if] 
        </div>
    </div>
</div>

<script type="text/javascript" src="/res/js/structure/struture.js"></script>
<script type="text/javascript" src="/res/js/common/common.js"></script>
<script type="text/javascript" src="/res/third/laydate/laydate.js"></script>
<script type="text/javascript" src="/res/third/layer/layer.js"></script>
<script type="text/javascript" src="/res/js/common/tppl.js"></script>
<script type="text/javascript" src="/res/third/laytpl/laytpl.js"></script>
<script type="text/javascript">
    $(function() { 
        initTab();
        initDate();
        initCompanyTip();
        initPeoTip();
        initBatchPayTip();
        initBatchShipTip();

        $('.radioModel input').click(function() {
            if(this.checked){
                $(this).parents('ul').find('.radioModel').removeClass('radioModelon');
                $(this).parent().addClass('radioModelon');
            }
        })
        $('.tan-resetOrder .closed').click(function(){
            $(this).parents('.tanbox').hide();
        });

        $('.tanbox .closed').click(function(){
            $(this).parents('.tanbox').hide();
        });
        
        $(".back-main .inner").css("minHeight",$(window).height()-200);
    });

    //tab绑定点击事件
    function initTab() {
        $('li[data-tab]').on('click', function() {
            var tab = $(this).attr('data-tab');
            if(tab == 1) {
                $('#state').val(1); //待付款
            } else if(tab == 2) {
                $('#state').val(2); //已付款
            } else if(tab == 3) {
                $('#state').val(3); //已发货
            } else {
                $('#state').val('');
            }
            $('#tab').val(tab);
            $('#orderForm input').not(':hidden').val('');
            search();
        });
    }

    //日期选择控件初始化
    function initDate() {
        var start = {
            elem: '#sdate',
            format: 'YYYY-MM-DD',
        [#if queryParam.edate??]
            max : '${queryParam.edate}',
        [/#if]
            choose: function(datas){
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas;//将结束日的初始值设定为开始日
            }
        };
        var end = {
            elem: '#edate',
            format: 'YYYY-MM-DD',
        [#if queryParam.sdate??]
            min : '${queryParam.sdate}',
            start : '${queryParam.sdate}',
        [/#if]
            choose: function(datas){
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };
        laydate(start);
        laydate(end);
    }

    //展示公司信息tip信息
    function initCompanyTip() {
        $('.dataTable .alltd .cname').hover(function() {
            [#if ispurchaser]
                var companyId = $(this).parents('table').attr('data-sellerCompanyId');
                var userId = $(this).parents('table').attr('data-sellerUserId');
            [#else]
                var companyId = $(this).parents('table').attr('data-buyerCompanyId');
                var userId = $(this).parents('table').attr('data-buyerUserId');
            [/#if]
            var $container = $(this).find('.tan-companyInfo');
            if($container.find('img[data-img=loading]').length > 0) {
                $.ajax({
                    url: '/order/loadCompanyTip',
                    type: 'post',
                    dataType: 'json',
                    cache: true,
                    data: {companyId: companyId, userId: userId},
                    success: function (obj) {
                        if (obj.success) {
                            $container.html(tppl($('#companyTip').html(), obj.obj));
                        }
                    }
                });
            }
        });
    }

    //展示收货人tip信息
    function initPeoTip() {
        $('.dataTable .peo').hover(function() {
            var orderId = $(this).parents('table').attr('data-orderId');
            var $container = $(this).find('.tan-peoInfo');
            if($container.find('img[data-img=loading]').length > 0) {
                $.ajax({
                    url: '/order/loadPeoTip',
                    type: 'post',
                    dataType: 'json',
                    cache: true,
                    data: {orderId: orderId},
                    success: function (obj) {
                        if (obj.success) {
                            $container.html(laytpl($('#peoTip').html()).render(obj.obj));
                        }
                    }
                });
            }
        });
    }

    //分批支付Tip
    function initBatchPayTip() {
        $('.pname[data-tip=batchPay]').hover(function() {
            var $container = $(this).parent().find('.pcdown');
            if($container.find('ul').length > 0) {
                //已经加载过，不再加载
                return;
            }
            var orderId = $(this).parents('table').attr('data-orderId');
            $.ajax({
                url : '/order/loadBatchPayTip',
                type : 'post',
                dataType : 'json',
                data : {orderId : orderId},
                success : function(data) {
                    if(data.success) {
                        $container.html(tppl($('#batchPayTip').html(), data.obj));
                    }
                    var sz=$container.find("li").length;  
                    $container.find("ul").width(110*sz); 
                    $container.find("em").css("left",110*sz+20);
                }
            });
        }, function() {
        });
    }

    //分批支付Tip
    function initBatchShipTip() {
        $('.pname[data-tip=batchShip]').hover(function() {
            var $container = $(this).parent().find('.pcdown');
            if($container.find('ul').length > 0) {
                //已经加载过，不再加载
                return;
            }
            var orderId = $(this).parents('table').attr('data-orderId');
            $.ajax({
                url : '/order/loadBatchShipTip',
                type : 'post',
                dataType : 'json',
                data : {orderId : orderId},
                success : function(data) {
                    if(data.success) {
                        $container.html(tppl($('#batchShipTip').html(), data.obj)); 
                    }
                    var sz=$container.find("li").length;  
                    $container.find("ul").width(110*sz); 
                    $container.find("em").css("left",110*sz+20);
                }
            });
        }, function() {
        });
    }

    function search() {
        $('#pageNo').val(1);
        $('#orderForm').submit();
    }

    function next() {
        goto(Number($('#pageNo').val()) + 1);
    }

    function pre() {
        goto(Number($('#pageNo').val()) - 1);
    }

    function goto(pageNo) {
        if(pageNo >= 1 && pageNo <= ${page.pages!}) {
            $('#pageNo').val(pageNo);
            $('#orderForm').submit();
        }
    }

    //补充说明校验&&字数显示
    function checkCancelInstr() {
        var cancelReason = $('#cancelOrderWin input[name=cancelReason]:checked').val();
        var cancelInstr = $('#cancelOrderWin textarea[name=cancelInstr]').val();
        if(cancelReason == '其他' && cancelInstr == '') {
            $('#cancelOrderWin .error').html('<i></i>请输入补充说明');
            $('#cancelOrderWin .error').show();
        } else {
            if(cancelInstr.length > 500) {
                $('#cancelOrderWin .error').html('<i></i>补充说明不能超过500字');
                $('#cancelOrderWin .error').show();
            } else {
                $('#cancelOrderWin .error').hide();
            }
        }
        $('#cancelOrderWin textarea[name=cancelInstr]').next().html(cancelInstr.length + '/500');   //字数实时显示
    }

    function showCancelOrderWin(orderId) {
        $('#cancelOrderWin input[name=orderId]').val(orderId);
        $('#cancelOrderWin .error').hide();
        $('#cancelOrderWin input[name=cancelReason]:eq(0)').prop('checked', true);
        $('#cancelOrderWin input[name=cancelReason]:eq(0)').click();
        $('#cancelOrderWin textarea[name=cancelInstr]').val('');
        checkCancelInstr();
        $('#cancelOrderWin').show();
    }
    
    function cancelOrder() {
        var orderId = $('#cancelOrderWin input[name=orderId]').val();
        var cancelReason = $('#cancelOrderWin input[name=cancelReason]:checked').val();
        var cancelInstr = $('#cancelOrderWin textarea[name=cancelInstr]').val();
        if(cancelReason == '') {
            $('#cancelOrderWin .error').html('<i></i>请选择一个原因');
            $('#cancelOrderWin .error').show();
            return;
        }
        checkCancelInstr();
        if($('#cancelOrderWin .error').is(':visible')) {
            return;
        }
        $.ajax({
            url : '/order/cancelOrder',
            type : 'post',
            dataType : 'json',
            data : {orderId : orderId, cancelReason : cancelReason, cancelInstr : cancelInstr},
            beforeSend : function() {
                layer.load(2, {shade: 0.1});
            },
            success : function(data) {
                if(data.success) {
                    layer.msg("取消订单成功");
                    $('#cancelOrderWin').hide();
                    var $tr = $('table[data-orderId=' + orderId + '] tr:eq(1)');
                    $tr.find('td:eq(3) div:eq(0)').html("交易关闭");
                    $tr.find("td:last").html("");
                } else {
                    layer.msg("取消失败");
                }
            },
            complete : function() {
                layer.closeAll('loading');
            }
        });
    }

    function showModifyPriceWin(orderId, totalPrice, originalPrice) {
        $('#modifyPriceWin input[name=orderId]').val(orderId);
        $('#modifyPriceWin input[name=maxPrice]').val(originalPrice);
        $('#modifyPriceWin span.orange').html('￥' + totalPrice);
        $('#modifyPriceWin').show();
    }

    //修改价格
    function modifyPrice() {
        var orderId = $('#modifyPriceWin input[name=orderId]').val();
        var maxPrice = $('#modifyPriceWin input[name=maxPrice]').val();
        var price = $('#modifyPriceWin input[name=price]').val();
        if(price == '') {
            layer.msg('请输入价格');
            return;
        }
        if(!/^([1-9]\d*|0)(\.\d{1,2})?$/.test(price)) {
            layer.msg('请输入正确的价格，最多保留小数点2位');
            return;
        }
        if(Number(price) <= 0 || Number(price) > maxPrice) {
            layer.msg('请输入正确的价格，不能超过' + maxPrice);
            return;
        }
        $.ajax({
            url : '/order/modifyPrice',
            type : 'post',
            dataType : 'json',
            data : {orderId : orderId, price : price},
            beforeSend : function() {
                layer.load(2, {shade: 0.1});
            },
            success : function(data) {
                if(data.success) {
                    layer.msg("操作成功");
                    $('#modifyPriceWin').hide();
                    var $tr = $('table[data-orderId=' + orderId + '] tr:eq(1)');
                    $tr.find('td:eq(2) b').html("¥" + Number(price).toFixed(2));
                } else {
                    layer.msg(data.msg);
                }
            },
            complete : function() {
                layer.closeAll('loading');
            }
        });
    }

    function goPay(orderId, payId) {
    [#if ispurchaser]
        [#if !adminOrfinance]
            layer.alert('您没有财务管理权限，请联系财务人员进行操作');
        [#else]
            window.open('/order/pay_on/' + orderId + '/' + payId);
        [/#if]
    [/#if]
    }
</script>
</body>
</html>